<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%used_car_estimate_order_log}}".
 *
 * @property int $id
 * @property int $used_car_estimate_order_id
 * @property int $created_at
 * @property string $serial_number
 * @property string $send_return_msg
 * @property string $api_return_code
 * @property string $api_return_msg
 * @property int $old_status
 * @property int $new_status
 * @property string $app_post_data
 * @property string $post_data
 * @property string $response_data
 *
 * @property UsedCarEstimateOrderBankBackLog[] $usedCarEstimateOrderBankBackLogs
 * @property UsedCarEstimateOrder $usedCarEstimateOrder
 */
class UsedCarEstimateOrderLog extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%used_car_estimate_order_log}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['used_car_estimate_order_id', 'created_at', 'serial_number'], 'required'],
            [['used_car_estimate_order_id', 'created_at', 'old_status', 'new_status'], 'integer'],
            [['app_post_data', 'post_data', 'response_data'], 'string'],
            [['serial_number', 'api_return_code'], 'string', 'max' => 20],
            [['send_return_msg', 'api_return_msg'], 'string', 'max' => 255],
            [['used_car_estimate_order_id'], 'exist', 'skipOnError' => true, 'targetClass' => UsedCarEstimateOrder::className(), 'targetAttribute' => ['used_car_estimate_order_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'used_car_estimate_order_id' => Yii::t('app', 'Used Car Estimate Order ID'),
            'created_at' => Yii::t('app', 'Created At'),
            'serial_number' => Yii::t('app', 'Serial Number'),
            'send_return_msg' => Yii::t('app', 'Send Return Msg'),
            'api_return_code' => Yii::t('app', 'Api Return Code'),
            'api_return_msg' => Yii::t('app', 'Api Return Msg'),
            'old_status' => Yii::t('app', 'Old Status'),
            'new_status' => Yii::t('app', 'New Status'),
            'app_post_data' => Yii::t('app', 'App Post Data'),
            'post_data' => Yii::t('app', 'Post Data'),
            'response_data' => Yii::t('app', 'Response Data'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUsedCarEstimateOrderBankBackLogs()
    {
        return $this->hasMany(UsedCarEstimateOrderBankBackLog::className(), ['for_serial_number' => 'serial_number']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUsedCarEstimateOrder()
    {
        return $this->hasOne(UsedCarEstimateOrder::className(), ['id' => 'used_car_estimate_order_id']);
    }
}
